<!-- 折线图 -->
<style lang="stylus" scoped>
.shejiaomultipless1
  height 100px
  background-size 100% 100%
  .main
    width 100%
    height calc(100% - 100px)
    margin-top -15px
</style>


<template>
<div class="shejiaomultipless1">
  <p class='titleshejiaomultipless1' style='font-family:微软雅黑;font-size:16px;color:#0B903C;font-weight:bold;line-height:50px;'>社区矫正人员矫正类别分布</p>
  <div class="main"></div>
</div>

</template>

<script>
import echarts from 'echarts'
import header from 'components/header/header'
import filter from 'components/filter/filter'
import axios from 'axios'
export default {
  data() {
    return {
      legendArr: [],
      color: this.$store.state.color,
      styleArr: [],
      myChart: {},
      name: ''
    }
  },
  watch: {
    too(val, oldVal) {
      console.log("watch=", val, oldVal)
    }
  },
  methods: {
    intclick() {
      console.log(global.token)
    },
    intchange() {
      alert(123);
    },
    _init() {
      this.myChart = echarts.init(document.querySelector('.shejiaomultipless1 .main'))
      var glo = this.GLOBAL.BASE_URL;
      this.myChart.on("click", function() {
        var xianname = localStorage.getItem('xianname');
        $(".table").show();
        $(".table iframe").attr("src", glo + "/a/shejiao/shejiaoMain/vuelist?county=" + xianname).show();
      })
      this.legendArr = this.myChart.getOption().series
      this.legendArr.forEach((data) => {
        data.selected = true;
      })
      this.$root.charts.push(this.myChart)
      window.addEventListener('resize', function() {
        this.myChart.resize()
      }.bind(this))
    }
  },
  components: {
    'v-header': header,
    'v-filter': filter
  },
  mounted() {
    // 基于准备好的dom，初始化echarts实例
    this.myChart = echarts.init(document.querySelector('.shejiaomultipless1 .main'))
    this.myChart.on("click", function(params) {
      // localStorage.setItem('areaname', params.name)
      // 点击事件判断name的值，获取name的type类型  全局变量total  遍历全局变量
      // location.href = "/#/shejiaobang2?areaname=" + params.name;
    })
    var areaname = localStorage.getItem('areaname');
    axios.get(this.GLOBAL.BASE_URL + '/a/sys/area/shejiaoData?name=' + areaname).then((res) => {
    // axios.get('static/data/Datas.json').then((res) => {
      if (res) {
        var arr = [];
        var shejiaoconame = [];
        var shejiaoco = res.data[0]['shejiaoco'].split(",");
        shejiaoco.pop()
        var seriesarr = [];
        $(shejiaoco).each(function(index, item) {
          var arr1 = [];
          arr = [];
          $(res.data).each(function() {
            if (this.name !== areaname) {
              arr[arr.length] = this.name;
              var arr2 = this.shejiaocorrectcount.split(",");
              arr2.pop();
              arr1[arr1.length] = arr2[index];
            }
          })
          shejiaoconame[shejiaoconame.length] = this;
          seriesarr[seriesarr.length] = {
            name: item,
            type: 'bar',
            data: arr1,
            itemStyle: {
              normal: {
                barBorderRadius: [5, 5, 0, 0],
                label: {
                  formatter: function (params) {
                    if (params.value > 0) {
                      return params.value;
                    } else {
                      return "";
                    }
                  },
                  show: true,
                  color: '#00AA5E',
                  position: 'top',
                  fontWeight: 'bold'
                }
              }
            }
          }
        })
        localStorage.setItem('areadata', JSON.stringify(res.data));
        this.myChart.setOption({
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          legend: {
            data: shejiaoconame
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: [
            {
              axisLine: {
                show: true,
                lineStyle: {
                  color: '#00AA5E'
                }
              },
              axisLabel: {
                rotate: 50,
                textStyle: {
                  color: 'rgba(11, 144, 60, 1)',
                  fontWeight: 'bold',
                  fontSize: '10'
                }
              },
              type: 'category',
              data: arr,
              splitLine: {
                show: false
              }
            }
          ],
          yAxis: [
            {
              axisLine: {
                show: true,
                lineStyle: {
                  color: '#00AA5E'
                }
              },
              axisLabel: {
                textStyle: {
                  color: 'rgba(11, 144, 60, 1)',
                  fontWeight: 'bold',
                  fontSize: '10'
                }
              },
              type: 'value',
              splitLine: {
                show: false
              }
            }
          ],
          series: seriesarr
        });
        this._init()
      }
    });
  }
}
</script>
